//
//  LZYFileTool.m
//  LZYDownLoaderDemo
//
//  Created by bjhj on 17/4/5.
//  Copyright © 2017年 刘占宇个人项目. All rights reserved.
//

#import "LZYFileTool.h"

@implementation LZYFileTool

+ (BOOL)createDirectoryIfNotExisits:(NSString *)path {
    
    NSFileManager *manager = [NSFileManager defaultManager];
    if(![manager fileExistsAtPath:path]){
        NSError *error;
        [manager createDirectoryAtPath:path withIntermediateDirectories:YES attributes:nil error:&error];
        if (error) {
            return NO;
        }
    }
    return YES;
}

+ (BOOL)isExistsWithFile: (NSString *)filePath {
    
    BOOL result = [[NSFileManager defaultManager] fileExistsAtPath:filePath];
    return result;
}

+ (long long)fileSizeWithPath: (NSString *)filePath {
    
    // 如果路径不存在, 返回0
    if (![self isExistsWithFile:filePath]) {
        return 0;
    }
    
    NSDictionary *fileInfoDic = [[NSFileManager defaultManager] attributesOfItemAtPath:filePath error:nil];
    long long fileSize = [fileInfoDic[NSFileSize] longLongValue];
    return fileSize;
}


+ (void)moveFile: (NSString *)fromPath toFile: (NSString *)toPath {
    // 如果路径不存在, 返回0
    if (![self isExistsWithFile:fromPath]) {
        return;
    }
    [[NSFileManager defaultManager] moveItemAtPath:fromPath toPath:toPath error:nil];
    
}

+ (void)removeFileAtPath: (NSString *)filePath {
    // 如果路径不存在, 返回0
    if (![self isExistsWithFile:filePath]) {
        return;
    }
    [[NSFileManager defaultManager] removeItemAtPath:filePath error:nil];
    
}
@end
